package com.ctrip.ec.biz.dao.member;
import com.ctrip.ec.dal.DaoBase;
import com.ctrip.ec.biz.entity.member.MemberOauthEntity;
import com.ctrip.ec.dal.DbAccess;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class MemberOauthDao extends DaoBase<MemberOauthEntity> {
    public MemberOauthDao() {
        super(MemberOauthEntity.class);
    }
    public MemberOauthDao(DbAccess db) {
        super(MemberOauthEntity.class,db);
    }

    public MemberOauthEntity entityByOpenId(String openId) throws SQLException {
        String sql = "select * from "  + this.getTableName() + " where open_id=? order by id desc";
        List<MemberOauthEntity> list = this.db.query(MemberOauthEntity.class,sql,openId);
        if(list.size()>0){
            return list.get(0);
        }else{
            return null;
        }
    }

    public MemberOauthEntity entity(Long memberId, String oauth) throws SQLException {
        String sql = "select * from " + this.getTableName() + " where member_id=? and oauth=?";
        List<MemberOauthEntity> list = this.db.query(MemberOauthEntity.class,sql,memberId,oauth);
        if(list.size()>0){
            return list.get(0);
        }else {
            return null;
        }
    }
}
